﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZPPProj01Logika;
using System.Data.SqlClient;
using System.Data;

namespace ZPPProj01Interface
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Baza baza;
        public MainWindow()
        {
            InitializeComponent();
            baza = new Baza();
            comboBox1.ItemsSource = baza.PobierListePracownikow()
                                        .Select(em => new ComboBoxItem { Uid = em.EmployeeID.ToString(), Content = em.LastName + ' ' + em.FirstName });
            
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            
            
        }

        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataTable tabela = new DataTable();
            DataColumn kolumna = new DataColumn("Miejscowość");
            tabela.Columns.Add(kolumna);

            DataRow wiersz;
            foreach (var y in baza.MiastaPracownika(Convert.ToInt32(comboBox1.SelectedValue)))
            {
                wiersz = tabela.NewRow();
                wiersz["Miejscowość"] = y.TerritoryDescription;
                tabela.Rows.Add(wiersz);
            }
            dataGrid1.ItemsSource = tabela.DefaultView;
            label2.Content = baza.Sprzedaz(Convert.ToInt32(comboBox1.SelectedValue));
        }
    }
}
